
package GUI;
import javax.swing.JTable;
import javax.swing.table.TableModel;

public class JanelaGerenciarCliente extends javax.swing.JFrame {    

    ControladorGerenciarCliente cGC;
    ControladorJanelaPrincipal cJC;
   

    public void setControladorJanelaPrincipal(ControladorJanelaPrincipal cJC) {
        this.cJC = cJC;
    }    
     
    public JanelaGerenciarCliente() {
        initComponents();
        setLocationRelativeTo(null);
    }
    /**
     * A classe Principal conhece a janelaGerenciarCliente
     */
    public void setControladorGerenciarCliente(ControladorGerenciarCliente c){
        cGC = c;
        botaoCadastrar.addActionListener(cGC);
        botaoExcluir.addActionListener(cGC);
        botaoPesquisarPorCPF.addActionListener(cGC);
        botaoPesquisarPorNome.addActionListener(cGC);
        botaoAtualizar.addActionListener(cGC);
        botaoAlterar.addActionListener(cGC);
        botaoSair.addActionListener(cGC);
        jTable1.addMouseListener(c);
        jTable1.setModel(new ModeloTabela());
    }


    public JTable getjTable1() {
        return jTable1;
    }

    public void setJTable (ModelTable mt)
    {
        try
        {
            jTable1.setModel((TableModel)mt);
        }catch (NullPointerException e)
        {
            e.getStackTrace();
        }
    }



    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelPrincipal = new javax.swing.JPanel();
        painelPesquisaPorCPF = new javax.swing.JPanel();
        botaoPesquisarPorCPF = new javax.swing.JButton();
        campoCPF = new javax.swing.JFormattedTextField();
        painelPesquisaPorNome = new javax.swing.JPanel();
        campoNome = new javax.swing.JTextField();
        botaoPesquisarPorNome = new javax.swing.JButton();
        botaoCadastrar = new javax.swing.JButton();
        botaoExcluir = new javax.swing.JButton();
        botaoAlterar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        labelListarClientes = new javax.swing.JLabel();
        botaoSair = new javax.swing.JButton();
        botaoAtualizar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Gerenciar Cliente");

        painelPrincipal.setBackground(new java.awt.Color(204, 204, 204));

        painelPesquisaPorCPF.setBackground(new java.awt.Color(204, 204, 204));
        painelPesquisaPorCPF.setBorder(javax.swing.BorderFactory.createTitledBorder("Pesquisa pelo CPF"));

        botaoPesquisarPorCPF.setFont(new java.awt.Font("Arial", 1, 12));
        botaoPesquisarPorCPF.setText("Pesquisar por cpf");

        try {
            campoCPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout painelPesquisaPorCPFLayout = new javax.swing.GroupLayout(painelPesquisaPorCPF);
        painelPesquisaPorCPF.setLayout(painelPesquisaPorCPFLayout);
        painelPesquisaPorCPFLayout.setHorizontalGroup(
            painelPesquisaPorCPFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelPesquisaPorCPFLayout.createSequentialGroup()
                .addComponent(campoCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoPesquisarPorCPF))
        );
        painelPesquisaPorCPFLayout.setVerticalGroup(
            painelPesquisaPorCPFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelPesquisaPorCPFLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelPesquisaPorCPFLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoPesquisarPorCPF))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        painelPesquisaPorNome.setBackground(new java.awt.Color(204, 204, 204));
        painelPesquisaPorNome.setBorder(javax.swing.BorderFactory.createTitledBorder("Pesquisa pelo Nome"));

        botaoPesquisarPorNome.setFont(new java.awt.Font("Arial", 1, 12));
        botaoPesquisarPorNome.setText("Pesquisar Por nome");

        javax.swing.GroupLayout painelPesquisaPorNomeLayout = new javax.swing.GroupLayout(painelPesquisaPorNome);
        painelPesquisaPorNome.setLayout(painelPesquisaPorNomeLayout);
        painelPesquisaPorNomeLayout.setHorizontalGroup(
            painelPesquisaPorNomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelPesquisaPorNomeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(campoNome, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botaoPesquisarPorNome))
        );
        painelPesquisaPorNomeLayout.setVerticalGroup(
            painelPesquisaPorNomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelPesquisaPorNomeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelPesquisaPorNomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoPesquisarPorNome))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        botaoCadastrar.setFont(new java.awt.Font("Arial", 1, 12));
        botaoCadastrar.setText("Cadastrar");
        botaoCadastrar.addActionListener(cGC);

        botaoExcluir.setFont(new java.awt.Font("Arial", 1, 12));
        botaoExcluir.setText("Excluir Cliente");
        botaoExcluir.addActionListener(cGC);

        botaoAlterar.setFont(new java.awt.Font("Arial", 1, 12));
        botaoAlterar.setText("Alterar Cliente");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.setModel(new ModeloTabela ());
        jScrollPane1.setViewportView(jTable1);
        jTable1.getSelectedRowCount();

        labelListarClientes.setFont(new java.awt.Font("Arial", 1, 12));
        labelListarClientes.setText("Lista de Clientes Cadastrados");

        botaoSair.setFont(new java.awt.Font("Arial", 1, 12));
        botaoSair.setText("Sair");

        botaoAtualizar.setText("Atualizar");

        javax.swing.GroupLayout painelPrincipalLayout = new javax.swing.GroupLayout(painelPrincipal);
        painelPrincipal.setLayout(painelPrincipalLayout);
        painelPrincipalLayout.setHorizontalGroup(
            painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelPrincipalLayout.createSequentialGroup()
                        .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 993, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, painelPrincipalLayout.createSequentialGroup()
                                .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(painelPrincipalLayout.createSequentialGroup()
                                        .addComponent(painelPesquisaPorNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(painelPesquisaPorCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(botaoCadastrar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(botaoExcluir, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)))
                                    .addComponent(labelListarClientes))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(botaoSair, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(botaoAlterar, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)))
                        .addContainerGap(21, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelPrincipalLayout.createSequentialGroup()
                        .addComponent(botaoAtualizar)
                        .addGap(64, 64, 64))))
        );
        painelPrincipalLayout.setVerticalGroup(
            painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelPrincipalLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(painelPesquisaPorCPF, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(painelPrincipalLayout.createSequentialGroup()
                            .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(botaoCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(botaoAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(botaoExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(botaoSair, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addComponent(painelPesquisaPorNome, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(painelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelPrincipalLayout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(labelListarClientes))
                    .addGroup(painelPrincipalLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoAtualizar)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(137, 137, 137))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(painelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
  
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoAlterar;
    private javax.swing.JButton botaoAtualizar;
    private javax.swing.JButton botaoCadastrar;
    private javax.swing.JButton botaoExcluir;
    private javax.swing.JButton botaoPesquisarPorCPF;
    private javax.swing.JButton botaoPesquisarPorNome;
    private javax.swing.JButton botaoSair;
    private javax.swing.JFormattedTextField campoCPF;
    private javax.swing.JTextField campoNome;
    private javax.swing.JScrollPane jScrollPane1;
    private static volatile javax.swing.JTable jTable1;
    private javax.swing.JLabel labelListarClientes;
    private javax.swing.JPanel painelPesquisaPorCPF;
    private javax.swing.JPanel painelPesquisaPorNome;
    private javax.swing.JPanel painelPrincipal;
    // End of variables declaration//GEN-END:variables


    public String getCampoNome() {
        return campoNome.getText();
    }

    public void setCampoNome(String campoNome) {
        this.campoNome.setText(campoNome);
    }
   
    public String getCampoCPF() {
        return campoCPF.getText();
    }

    public void setCampoCPF(String campoCPF) {
        this.campoCPF.setText(campoCPF);
    }
    // End of variables declaration

    




    public String getBotaoCadastrarCliente(){
        return botaoCadastrar.getName();
    }

    public String getBotaoExcluir() {
        return botaoExcluir.getName();
    }




}
